<template>
<div>
    <div class="xuanxiang">
        <ul>
            <li style="color:#c1602d">综合</li>
            <li>新品</li>
            <li>销量</li>
            <li>价格<span class="iconfont icon-shangxia"></span></li>
        </ul>
        <div class="car"><span class="iconfont icon-gouwuche1"></span></div>
        <div id="back"><span class="iconfont icon-xiangshang"></span></div>
    </div>
    <div class="xx" style="display:block">
       <div class="right" v-for="(xinpins,index) in xinpin" :key="index">
        <img :src="xinpins.goodsImg" @click="xiangqing(xinpins.id)">
        <div class="right-1">{{xinpins.goodsName}}</div>
        <div class="right-2">
            <div class="cup21">￥{{xinpins.goodsLowPrice}}</div>
            <div class="cup22">￥{{xinpins.goodsHighPrice}}</div>
        </div><br>
        <p>已售卖{{xinpins.saleNumber}}件</p>
        <div class="right-4"  @click="add"><span class="iconfont icon-gouwuche1"></span></div>
       </div> 
    </div>
    <div class="xx">
        <div class="right" v-for="(xinpins,index) in xinpin" :key="index">
        <img :src="xinpins.goodsImg" @click="xiangqing(xinpins.id)">
        <div class="right-1">{{xinpins.goodsName}}</div>
        <div class="right-2">
            <div class="cup21">￥{{xinpins.goodsLowPrice}}</div>
            <div class="cup22">￥{{xinpins.goodsHighPrice}}</div>
        </div><br>
        <p>已售卖{{xinpins.saleNumber}}件</p>
        <div class="right-4"  @click="add"><span class="iconfont icon-gouwuche1"></span></div>
        </div>
    </div>
    <div class="xx">
        <div class="right" v-for="(xiaoliangs,index) in xiaoliang" :key="index">
        <img :src="xiaoliangs.goodsImg" @click="xiangqing(xiaoliangs.id)">
        <div class="right-1">{{xiaoliangs.goodsName}}</div>
        <div class="right-2">
            <div class="cup21">￥{{xiaoliangs.goodsLowPrice}}</div>
            <div class="cup22">￥{{xiaoliangs.goodsHighPrice}}</div>
        </div><br>
        <p>已售卖{{xiaoliangs.saleNumber}}件</p>
        <div class="right-4"  @click="add"><span class="iconfont icon-gouwuche1"></span></div>
        </div>
    </div>
    <div class="xx">
        <div class="right" v-for="(jiages,index) in jiage" :key="index">
        <img :src="jiages.goodsImg" @click="xiangqing(jiages.id)">
        <div class="right-1">{{jiages.goodsName}}</div>
        <div class="right-2">
            <div class="cup21">￥{{jiages.goodsLowPrice}}</div>
            <div class="cup22">￥{{jiages.goodsHighPrice}}</div>
        </div><br>
        <p>已售卖{{jiages.saleNumber}}件</p>
        <div class="right-4"  @click="add"><span class="iconfont icon-gouwuche1"></span></div>
        </div>
    </div>
    <div id="num"><span class="sp">{{$store.state.num}}</span></div>    
</div>

</template>
<script>
import axios from "axios"
export default {
    data(){
        return {
            xinpin:[],
            xiaoliang:[],
            jiage:[],
            num:"0"
        }
    },
    methods:{
    add(){
        var oNum = document.getElementById('num');
        oNum.style.display='block';
        this.$store.state.num++
    },
    xiangqing(goodid){
        this.$router.push("/Goods2/"+goodid)
    }
    },
    mounted(){
        var oBack =document.getElementById('back')
        window.onscroll=function(){
        var oTop =document.body.scrollTop ||document.documentElement.scrollTop;
        if (oTop>=1000){
            oBack.style.display = "block"
        }else{
            oBack.style.display = 'none'
        } 
    };
        var oLi = document.querySelectorAll('li')
        var oR = document.querySelectorAll('.xx')
        console.log(oR);
        for(var i=0;i<oLi.length;i++){
            oLi[i].index=i
            oLi[i].onclick=function(){
                for (var j = 0; j < oLi.length; j++) {
                    oLi[j].style.color='#737373'
                    oR[j].style.display='none'
                }
                this.style.color='#c1602d'
                oR[this.index].style.display='block'
            }   
        }
    },
    created(){
        // console.log(1);
        axios({
            url:"/api/goods/findGoodsByTime",
            params:{
                typeId:10000
            },
            
        })
        .then(res=>{
            if(res.data.code=='1'){
                // console.log('查询成功');
                this.xinpin=res.data.data
                // console.log(res.data.data)
            }else{
                // console.log('查询失败');
            }
        }),
        axios({
            url:"/api/goods/findGoodsBySaleNumber",
            params:{
                typeId:10000
            },
        })
        .then(res=>{
            if(res.data.code=='1'){
                // console.log('查询成功');
                this.xiaoliang=res.data.data
                // console.log(res.data.data)
            }else{
                // console.log('查询失败');
            }
        }),
        axios({
            url:"/api/goods/findGoodsByPrice",
            params:{
                typeId:10000
            },
        })
        .then(res=>{
            if(res.data.code=='1'){
                // console.log('查询成功');
                this.jiage=res.data.data
                // console.log(res.data.data)
            }else{
                // console.log('查询失败');
            }
        })
    },
}
</script>
<style scoped>
@import url("../assets/font_2735397_jcfueec7nca/iconfont.css");
.xuanxiang{
    width: 3.04rem;
    height: 0.2rem;
    margin: auto;
    color: #737373;
    font-size: 0.14rem;
}
ul{
    display: flex;
    justify-content: space-between
}
.car{
    width: 0.3rem;
    height: 0.3rem;
    float: right;
    border-radius: 50%;
    background-color: #3d2d99ca;
    font-size: 0.1rem;
    color: #fff;
    line-height: 0.3rem;
    text-align: center;
    margin-right: 0.05rem;
    position: fixed;
    right: 0.1rem;
    bottom: 2.25rem;
    z-index: 99;
}
#back{
    width: 0.3rem;
    height: 0.3rem;
    float: right;
    border-radius: 50%;
    background-color: white;
    font-size: 0.1rem;
    color: #737373;
    line-height: 0.3rem;
    text-align: center;
    margin-right: 0.05rem;
    position: fixed;
    right: 0.10rem;
    bottom: 1.80rem;
    z-index: 99; 
}
.right{
    margin-left: 0.1rem;
    width: 1.65rem;
    height: 2.24rem;
    margin-top: 0.1rem;
    background-color: #fff;
    float: left;
    border-radius: 0.04rem;
}
.xx{
    display: none;
}
.right-1{
    height: 0.28rem;
    font-size: 0.11rem;
    margin-left: 0.12rem;
    text-overflow: ellipsis;
    overflow: hidden;
}
.right-2{
    margin-top: 0.1rem;
    margin-left: 0.09rem;
}
.right-3{
    width: 0.22rem;
    height: 0.12rem;
    font-size: 0.08rem;
    line-height: 0.12rem;
    color: #ed9878;
    background-color: #fce4db;
    margin-bottom: 0.08rem;
    margin-left: 0.09rem;
}
.right-4{
    width: 0.18rem;
    height: 0.18rem;
    float: right;
    border-radius: 50%;
    background-color: #e63900;
    font-size: 0.1rem;
    color: #fff;
    line-height: 0.18rem;
    margin-right: 0.05rem;
}
img{
    width: 100%;
    height: 1.23rem;
    border-top-left-radius: 0.05rem;
    border-top-right-radius: 0.05rem;
}
.cup21{
    float: left;
    font-size: 0.12rem;
    color: #eb8a53;
}
.cup22{
    float: left;
    font-size: 0.12rem;
    color: #8d8f8c;
    text-decoration: line-through;
    margin-left: 0.07rem;
}
p{
    display: block;
    width: 1rem;
    float: left;
    font-size: 0.1rem;
    color: #878787;
    margin-left: 0.09rem;
}
#num{
    width: 0.16rem;
    height: 0.12rem;
    background-color: red;
    color: #fff;
    font-size: 0.10rem;
    position: fixed;
    right: 0.1rem;
    bottom: 2.44rem;
    text-align: center;
    line-height: 0.12rem;
    z-index: 999;
    border-radius: 0.27rem;
    display: none;
}
</style>
